package com.kuzan.autocloud.common.repository.system;

import com.kuzan.autocloud.common.model.system.ACPermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * <p>Description: </p>
 *
 * @author kuzank
 */
@Repository
public interface ACPermissionRepository extends JpaRepository<ACPermission, String> {

    @Query(value = "" +
            "(select a.id,u0.title,u0.avatar from sys_permission a join sys_organization_person u0 on a.identity = u0.id where a.resource = ?1)" +
            " union all " +
            "(select a.id,u0.title,u0.avatar from sys_permission a join sys_organization u0 on a.identity = u0.id where a.resource = ?1)" +
            " union all " +
            "(select a.id,u0.title,u0.avatar from sys_permission a join sys_organization_rolegroup u0 on a.identity = u0.id where a.resource = ?1)", nativeQuery = true)
    List<Map> findByResource(String resource);
}
